from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait


class PageObject():

    def __init__(self, driver):
        self.driver = driver

    # 定义元素查找函数
    def findOne(self,*args):
        WebDriverWait(self.driver,10,poll_frequency=0.5).until(
            expected_conditions.presence_of_element_located(args))
        return self.driver.find_element(*args)


    # 定义查找多个元素
    def findMany(self,*args):
        WebDriverWait(self.driver,10,poll_frequency=0.5).until(
            expected_conditions.presence_of_element_located(args))
        return self.driver.find_elements(*args)


    # 定义点击函数
    def click(self,*args):
        WebDriverWait(self.driver,10,poll_frequency=0.5).until(
            expected_conditions.presence_of_element_located(args))
        return self.driver.find_element(*args).click()


    # 输入内容
    def send(self,*args,content):
        WebDriverWait(self.driver,10,poll_frequency=0.5).until(
            expected_conditions.presence_of_element_located(args))
        return self.driver.find_element(*args).send_keys(content)


    # 切换frame
    def switchFrame(self,frame):
        self.driver.switch_to.frame(frame)


    # 截图
    def getErrorImage(self,name):
        self.driver.get_screenshot_as_file(name)


